<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>Title</title>
  </head>
  <script src="./src/lib/web3.min.js"></script>
  <script src="./src/lib/bignumber.js"></script>
  <script src="./src/back_main.js" type="module"></script>

  <body>
    <button onclick="connect()">链接</button>
    <button id="approve" style="display: block" onclick="isApprovedToken()">
      isApprovedToken
    </button>
    <!-- <button onclick="transferFrom()">转账Usdt</button> -->
    <button id="deposit">存1000btc</button>
    <button onclick="getDepositInfo()">查存的btc</button>
    <button onclick="withdraw()">取款500btc</button>
  </body>
  <script type="module">
    import {
      connect,
      deposit,
      getBalance,
      getTokenAddress,
      queryAssetList,
      withdraw,
      getTitles,
      getAssetInfo,
      invest,
      getPairInfo,
      queryPairsList,
      getPairAdressFromTokens,
      getTokensFromPair,
      getTokenPoolAddress,
      approveToken,
      repay,
      getLiquidityAmount,
      divest,
      getTokenPrices,
      _getKeepInsterestRatio,
        fetchData,
        getRepayInfo,
        getAssetsList,
        getPairList,
        getUserInfoList,
        getInvestInfo,
        getAddInfo,
        getDivestInfo
    } from "./src/back_main.js";

    // console.log(fetchData);

    connect(function (action, data) {
      console.log(action, data);
    }).then(console.log);

    setTimeout(async () => {
      // deposit(
      //   "0x1eCb3e38690eA23F3cDC5d1BEf2963Fe9153CF54",
      //   1000,
      //   (code, res) => {
      //     console.log(code, res);
      //   }
      // );
      //   await approveToken("0xB150C21e861b240edA37eFf1Ab34992622d4329D");
      // invest(
      //     "0x1F6E1b2864E430A09ad88e3C9E2cf40463897AD1",
      //   "1000",
      //   "2",
      //     "0xB150C21e861b240edA37eFf1Ab34992622d4329D",
      //   "1234",
      //   "1647918824",
      //   (code, res) => {
      //     console.log(code, res);
      //   }
      // );

      // withdraw(
      //   '0x79Be5d6bCcc2437C62FEa49A7725Ba80b5c9ad70',
      //   "5",
      //   function (code, msg) {
      //     console.log(code, msg);
      //   }
      // );

      // divest(
      //   "0x464Ad1ae0381E98b6e43508F61Aed1c6d7088B4b",
      //   "100",
      //   "0xBff5437f3B9d4C8B3588f64eB31A40548D18A273",
      //   "0xB150C21e861b240edA37eFf1Ab34992622d4329D",
      //   "1647918824",
      //   (code, res) => {
      //     console.log(code, res);
      //   }
      // );

      // repay(
      //   "0x5dbCA58c7A11A0870e19eEB64bc72b478728d8B7",
      //   "0x1eCb3e38690eA23F3cDC5d1BEf2963Fe9153CF54",
      //   "1"
      // ,(code, res) => {
      //   console.log(code, res);
      // });

      // let t = getLiquidityAmount(
      //   "0x79Be5d6bCcc2437C62FEa49A7725Ba80b5c9ad70",
      //   "0x1eCb3e38690eA23F3cDC5d1BEf2963Fe9153CF54",
      //   "0",
      //   "0"
      // );

      // await approveToken(
      //   "0xD3681D676DFC3271478Ce8492742F76fd37e04f1",
      //   (code, res) => {
      //     console.log(code, res);
      //   }
      // )
      //   await approveToken("0xBff5437f3B9d4C8B3588f64eB31A40548D18A273");
      await fetchData();
      // console.log(await getTitles())
      // console.log(await getRepayInfo("0x464Ad1ae0381E98b6e43508F61Aed1c6d7088B4b", "0xB150C21e861b240edA37eFf1Ab34992622d4329D", 100));
      console.log(await getPairList());
      // console.log(await getUserInfoList());
      // console.log(await getInvestInfo("0x0e0C06C329F7ED91ffc951cef48f90FC98ee8Ae6", 2500, 100, "0x721aEda9c81ADAc92dFc9248127C219D91036671", 3));
      // console.log(await getAddInfo("0x464Ad1ae0381E98b6e43508F61Aed1c6d7088B4b", 10000, 10, "0xBff5437f3B9d4C8B3588f64eB31A40548D18A273"));
      // console.log(await getDivestInfo("0x464Ad1ae0381E98b6e43508F61Aed1c6d7088B4b", 1, "0xB150C21e861b240edA37eFf1Ab34992622d4329D", "0xB150C21e861b240edA37eFf1Ab34992622d4329D"));

      // let t = await getTokenPrices("BTC");

      // let t = await getPairInfo("0x5dbCA58c7A11A0870e19eEB64bc72b478728d8B7");
      // let t = await getAssetInfo("0x79Be5d6bCcc2437C62FEa49A7725Ba80b5c9ad70");
      // let t = await getTitles();
      // let t =await getTokenPoolAddress("0x913330eA64DbFF341dCC8ACC09022Dec03a56464");
      // let t = await getTokensFromPair(
      //   "0x2d1D1bd324d8D8F824E6f35568fea99A022E958e"
      // );
      // let t = await getPairAdressFromTokens(
      //   "0x79Be5d6bCcc2437C62FEa49A7725Ba80b5c9ad70",
      //   "0x1eCb3e38690eA23F3cDC5d1BEf2963Fe9153CF54",
      //   0
      // );
      // let t=await _getKeepInsterestRatio("0x79Be5d6bCcc2437C62FEa49A7725Ba80b5c9ad70");
      // console.log("---------t------------>>>>>>", t);
      // approveToken(
      //   "0x1eCb3e38690eA23F3cDC5d1BEf2963Fe9153CF54",
      //   function (code, msg) {
      //     console.log("approve result ", code, msg);
      //   }
      // );
    }, 1500);

    async function isApprovedToken() {
      let btcpooladdress = await BACK_MAIN.getTokenPoolAddress(
        BACK_CONST.ContractAddress[BACK_MAIN.chainId].BTC
      );
      let isApproved = await BACK_MAIN.isApprovedToken(
        BACK_CONST.ContractAddress[BACK_MAIN.chainId].BTC,
        btcpooladdress.data.tokenPool
      );
      console.log(isApproved);
      // document.getElementById("approve").style.display = "none";
    }
    function transferFrom() {
      BACK_MAIN.transferFrom(
        "0x7A68E46aeF8323b7c5e6cb06C85c42949dAcfa93",
        "0xc03C12101AE20B8e763526d6841Ece893248a069",
        "0x9336f0AcaFF9E3510365cb74bB27B0b4760f19cC",
        "5",
        function (code, msg) {
          console.log(code, msg);
        }
      );
    }
  </script>
</html>
